package com.sys.service.impl;

import com.sys.bean.History;
import com.sys.mapper.HistoryMapper;
import com.sys.service.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class HistoryServiceImpl implements HistoryService {
    @Autowired
    private HistoryMapper historyMapper;
    @Override
    public List<History> selectAll() {
        return historyMapper.selectAll();
    }

    @Override
    public List<Integer> selectCarIdByParkId(Integer parkId) {
        return historyMapper.selectCarIdByParkId(parkId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void insert(Integer parkId, Integer[] carIds) {
        //删除某个停车场和车辆的关联关系
        historyMapper.delete(parkId);
        if (carIds != null && carIds.length > 0){
            //添加新的关联关系
            historyMapper.insertCarIdAndParkId(parkId, carIds);
        }


    }

    @Override
    public List<Integer> selectByParkId(Integer parkId) {
        List<Integer> list = historyMapper.selectByParkId(parkId);
        return (list);
    }
}
